//
//  SettingSoundCell.m
//  SportSocial
//
//  Created by hanfangyu on 15/2/11.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "SettingSoundCell.h"
#import "AppDelegate.h"

@implementation SettingSoundCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.soundSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.contentView.width - 60, (self.contentView.height - 31)/2, 60, 31)];
        self.soundSwitch.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin;
        [self.soundSwitch addTarget:self action:@selector(onSwitchChange:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:self.soundSwitch];
        
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        self.soundSwitch.on = [[userDefault objectForKey:@"SoundAlert"] boolValue];
        
    }
    return self;
}

- (void)onSwitchChange:(UISwitch *)soundSwitch
{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:[NSNumber numberWithBool:soundSwitch.on] forKey:@"SoundAlert"];
    [userDefault synchronize];
    
    AppDelegate *appdelegate = [UIApplication sharedApplication].delegate;
    [appdelegate registerNotificaton];
}
@end
